package com.example.wendao.model.db.dao;

import androidx.paging.DataSource;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.example.wendao.model.entity.News;
import com.example.wendao.model.entity.User;


@Dao
public interface UserDao {

    @Insert
    void register(User user);

    @Query("SELECT * FROM users WHERE username =:username AND password =:password")
    User login(String username,String password);

    // 根据用户id查找用户
    @Query("SELECT * FROM users WHERE userId = :id")
    User findUserById(int id);

    //根据用户名模糊查找用户
    @Query("SELECT * FROM users WHERE username like '%' || :username || '%'")
    DataSource.Factory<Integer, User> findUserByName(String username);

    @Query("SELECT * FROM users")
    DataSource.Factory<Integer, User> queryAllUser();

    //根据多个id查询用户列表
    @Query("select * from users where userId in (:userids)")
    DataSource.Factory<Integer, User> findSomeUsersByUserIds(String userids);



    @Query("select * from users where username =:username")
    User findUserName(String username);

    @Update
    void updateUser(User user);

    @Insert
    void insertUser(User[] users);

    @Delete
    int delUser(User user);

}

